<!DOCTYPE html>
<html th:lang="${language}" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <th:block th:include="include :: header(#{okr.my})" />
  <th:block th:include="include :: okr-css" />
</head>
<body class="gray-bg">
<div class="container-div">
  <div class="row" >
    <div class="col-sm-12 search-collapse collapse">
      <form id="okr_search_form">
        <div class="select-list hidden">
          <ul class="row">
            <li class="col-xs-12 col-sm-6 col-md-4 hidden">
              <label>周期ID：</label>
              <input type="text" name="cycleId"   id="cycleId"/>
            </li>
            <li class="col-xs-12 col-sm-6 col-md-4">
              <a class="btn btn-primary btn-rounded btn-sm"
                 onclick="$.table.search('okr_search_form')">
                <i class="fa fa-search"></i>&nbsp;搜索</a>
              <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()">
                <i class="fa fa-refresh"></i>&nbsp;重置</a>
            </li>
          </ul>
        </div>
      </form>
    </div>
    <div class="btn-group-sm" id="toolbar" role="group">
      <div class="btn-group">
        <select class="form-control" data-style="btn-success"  id="cycleIdSelect"  th:onchange="changeCycleType()">
          <optgroup th:label="#{okr.yearChoice}">
            <div th:each="cycle : ${cycleList}">
              <div th:if="${cycle.cycleType == 1}">
                                <span th:if="${cycle.status == 0}">
                                        <option th:value="${cycle.id}" th:text="${cycle.cycleName}"></option>
                                </span>
                <span th:if="${cycle.status == 1}">
                                        <option th:value="${cycle.id}" th:text="${cycle.cycleName}"></option>
                                </span>
              </div>
            </div>
          </optgroup>
          <optgroup th:label="#{okr.quarterChoice}">
            <div th:each="cycle : ${cycleList}">
              <div th:if="${cycle.cycleType == 0}">
                                <span th:if="${cycle.status == 0}">
                                        <option th:value="${cycle.id}" selected="selected" th:text="${cycle.cycleName}"></option>
                                </span>
                <span th:if="${cycle.status == 1}">
                                        <option th:value="${cycle.id}" th:text="${cycle.cycleName}"></option>
                                </span>
              </div>
            </div>
          </optgroup>
        </select>
      </div>
      <span class="badge badge-success">      以下目标同子目标之间的进度差异过大（超过 15.00%)</span>
    </div>
    <div class="col-sm-12 select-table table-striped">
      <table id="bootstrap-table"></table>
    </div>
  </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: comment-js" />
<th:block th:include="include :: qqFace" />
<script th:inline="javascript">
  var prefix = ctx + "analysis";
  $(function () {
    var options = {
      url: prefix + "/list",
      ajaxParams:{"cycleId":$("#cycleIdSelect").val()},
      showSearch: false,
      columns: [
        {
          field: 'selectItem',
          checkbox: false
        },
        {
          field: 'okrId',
          visible: false
        },
        {
          field: 'userName',
          title: '负责人'
        },
        {
          field: 'content',
          title: [[#{okr.content}]],
        },
        {
          field: 'process',
          title: [[#{okr.progress}]],
          formatter: function (value, row, index) {
            return '<span class="badge badge-success">' + value  + '%</span>';
          }
        },
        {
          field: 'operation',
          title: '操作',
          formatter: function (value, row, index){
            let actions = [];
            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="showView(' + row.okrId + ')"><i class="fa fa-edit"></i>[(#{okr.view})]</a>');
            return  actions.join('');
          }

        }
        ]
    };
    $.table.init(options);
  });

  function showView(id){
    $.modal.openTab("OKR详情页面", ctx + "okr/info/view/" + id)
  }

  //OKR 周期切换
  function changeCycleType(type) {
    var cycleId = $("#cycleIdSelect").val();
    $("#cycleId").val(cycleId);
    $.table.search();
  }

</script>
</body>
</html>